package com.jiazhong.front.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiazhong.commons.Mapper.OrderItemMapper;
import com.jiazhong.commons.Mapper.OrderMapper;
import com.jiazhong.commons.Util.JsonResult;
import com.jiazhong.commons.Util.ResultTool;
import com.jiazhong.commons.bean.Order;
import com.jiazhong.commons.bean.OrderItem;
import com.jiazhong.front.service.OrderService;
import jakarta.annotation.Resource;

import java.util.Set;

public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private OrderItemMapper orderItemMapper;
    @Resource
    private OrderMapper orderMapper;

    @Override
    public JsonResult addOrder(Order order) {
        int b = orderMapper.insert(order);
        if (b > 0) {
            String orderId = order.getId();
            Set<OrderItem> orderItems = order.getOrderItems();
            orderItems.forEach(e -> {
                e.setOrderId(orderId);
                orderItemMapper.insert(e);
            });
        }
        return ResultTool.success("success");
    }
}